package com.touchapk.javafx;

import java.io.File;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.application.Application;
import javafx.stage.Stage;

public class Main extends Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Application.launch(Main.class, (java.lang.String[]) null);
    }

    @Override
    public void start(Stage primaryStage) {
        try {
            // Use one of the following to change the Language 
            //  ar: Arabic  (will resolve I18N keys against Bundle.properties_ar)
            //  en: English (will resolve I18N keys against Bundle.properties)
            //  fr: French  (will resolve I18N keys against Bundle.properties_fr)
            //  iw: Hebrew  (will resolve I18N keys against Bundle.properties_iw) 
        	
        	  Locale defaultLocale = Locale.getDefault();
        	  String language =defaultLocale.toString(); // <-- EDIT THIS
            //String language = "ar"; // <-- EDIT THIS
            
          

            Locale fakeLocale = new Locale(language);
            ResourceBundle i18nBundle = ResourceBundle.getBundle("com.touchapk.javafx.Bundle", fakeLocale);

            MainController mainController=new MainController(primaryStage,i18nBundle);
            String remember=SelectController.getProperties("remember","0");
            String path=SelectController.getProperties("path",System.getProperty("user.home"));
            boolean flag=false;
        	if("1".equals(remember)&&!path.equals(System.getProperty("user.home"))){
				File file=new File(path);
				if(file.exists()){
					flag=true;
				}
			}
        	
            if(flag){
            	mainController.setPath(path);
            	mainController.getTouchDialog().show();
            }else{
            	 FXMLDialog selectDialog = mainController.getSelectDialog();
            	 selectDialog.setTitle(i18nBundle.getString("application.title"));
                 selectDialog.setResizable(false);
                 selectDialog.show();
            }
           
            
        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}